# If you're reading this, you're doing it wrong.
from random import randint,shuffle
print("Philip Daian's Vocab Review Program\nhttp://nerd.nu/, licensed under GPL.")
reverse = raw_input("\nReverse or normal mode? ").lower()
if "reverse" in reverse:
   print "Reverse mode.  Definitions will show first."
   reverse = True
else:
   print "Normal mode."
   reverse = False
try:
    vocab = open("vocab.txt").read().splitlines()
except:
    print("Error.  Make sure the file vocab.txt is in the same directory as this script.")
vocab = [x.split("^^",1) for x in vocab]
shuffle(vocab)
while True:
    if len(vocab) == 0:
        break
    whee = vocab.pop()
    if reverse:
        whee.reverse()
    print(whee[0])
    if reverse:
        raw_input("Press return to view the word.")
    else:
        raw_input("Press return to view the definition")
    print '_____________\n\n', whee[1], '\n_____________\n'
    answer = raw_input("Did you get it? Type y or n. ")
    if "y" in answer:
        print "Okay.  Removing from stack.","\n"*3
    else:
        print "Keeping in stack.", "\n"*3
        if len(vocab)>3:
           vocab.insert(randint(0, len(vocab)-2), whee)
        else:
           vocab.insert(randint(0,len(vocab)),whee)

raw_input("Congrats, you finished.  Bye!")
    
    
